package edu.java.texbooks.scjp.test05;

public class CommonStudent extends Student implements Comparable {

    public CommonStudent(String name, int[] marks) {
	super(name, marks);
    }

    // before Java5 realization
    @Override
    public int compareTo(Object object) {
	if (object == null) {
	    throw new IllegalArgumentException(
		    "Null-pointed object in compareTo method");
	}
	CommonStudent student = null;
	if (object instanceof CommonStudent) {
	    student = (CommonStudent) object;
	} else {
	    throw new IllegalArgumentException(
		    "Illegal input argument for campareTo method of Student class");
	}

	return getName().compareTo(student.getName());
    }

    public int compareTo2(Object object) {
	if (object == null) {
	    throw new IllegalArgumentException(
		    "Null-pointed object in compareTo2 method");
	}
	CommonStudent student = null;
	if (object instanceof Student) {
	    student = (CommonStudent) object;
	} else {
	    throw new IllegalArgumentException(
		    "Illegal input argument for campareTo method of Student class");
	}

	return (int) (this.getAverageResults() - student.getAverageResults());
    }
}
